package leetcode;

/**
 * 整数反转  
 */
public class LeetCode7 {
    public int reverse(int x) {
        if (x == 0) {
            return x;
        }
        int res = 0;
        while (x != 0) {
            int temp = x % 10;
            if (res > Integer.MAX_VALUE / 10 || res < Integer.MIN_VALUE / 10) {
                return 0;
            }
            res = res * 10 + temp;
            x = x / 10;
        }
        return res;
    }

    public static void main(String[] args) {
        LeetCode7 leetCode07 = new LeetCode7();
        System.out.println(leetCode07.reverse(-123));
    }
}
